/*
 * Written by Dustin Striplin
 */

package View;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * Creates a window with a scroll bar that a manuscript can be
 * displayed in
 * @author dustin striplin
 *
 */
public class ManuscriptView extends JFrame{
	public static final int WIDTH = 800;
	public static final int HEIGHT = 550;
	
	public ManuscriptView(){
		
	}
	
	public ManuscriptView(final String title){
		this.setTitle(title);
	}
	
	
	/**
	 * Start this beast up
	 * @param manuscript The text to display
	 */
	public void start(final String manuscript) {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setSize(WIDTH, HEIGHT);
		this.setTitle("Manuscript");
		this.setResizable(true);
		this.setLocationRelativeTo(null);		//set in the middle of the screen
		this.add(createDisplay(manuscript));

		
		this.setVisible(true);
	}
	
	
	/**
	 * Creates the text area, populates it, and adds it to a JScrollPane
	 * @param manuscript
	 * @return a jscrollpane containing the text
	 */
	private JScrollPane createDisplay(final String manuscript) {

		JTextArea scriptView = new JTextArea(manuscript);
		scriptView.setBackground(Color.WHITE);
		scriptView.setLineWrap(true);
		scriptView.setEditable(false);
		JScrollPane container = new JScrollPane(scriptView);
		container.setBackground(Color.WHITE);
		container.setPreferredSize(new Dimension(WIDTH, HEIGHT));
	
		return container;
	}

}
